#include "useful_responses.h"
#include <fmt/core.h>
#include <fmt/format.h>
#include "../util/mime_type.h"
#include <string_view>
#include "../http/response_builder.h"
#include <string>

using namespace ::std::string_view_literals;

namespace wilson::http
{
    server::response useful_response(int s)
    {
        return useful_response(static_cast<status>(s));
    }

    server::response useful_response(status s)
    {
        auto str = to_string(s);
        auto body = fmt::format(
            "<html>Cans Server::Error Occured! code = {}, "
            "description = {}. "
            "Powered by Canary2, Wilson made it.</html>", 
            static_cast<size_t>(s), 
            str
        );
        auto type = fmt::format(
            "{}; charset=utf-8", 
            util::get_mime_type(".html"sv)
        );
        server::response_builder respb;
        respb.set_status(s);
        respb.set_version(version::HTTP_1_1);
        respb.set_header("Content-Type", type);
        respb.set_header("Content-Length", ::std::to_string(body.size()));
        respb.set_body(body);
        return respb.generate();
    }
}
